# Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=linux-valve-jupiter
pkgver=6.11
pkgrel=2
pkgdesc="Valve Steam Deck kernel fork"
arch="x86_64"
_flavor="valve-jupiter"
_carch="x86"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	pmb:kconfigcheck-uefi
	"
makedepends="
	bash
	bison
	elfutils-dev
	findutils
	flex
	linux-headers
	openssl-dev
	perl
	postmarketos-installkernel
"

# Source
_config="config-$_flavor.$arch"
case $pkgver in
	*.*.*)	_kernver=${pkgver%.0};;
	*.*)	_kernver=$pkgver;;
esac

source="
	https://git.kernel.org/torvalds/t/linux-${_kernver//_/-}.tar.gz
	$_config

	0001-ACPICA-Limit-error-message-flood-caused-by-firmware-.patch
	0002-drivers-video-backlight-Disable-backlight-notificati.patch
	0003-iio-light-ltrf216a-Return-floating-point-values.patch
	0004-mfd-Add-MFD-core-driver-for-Steam-Deck.patch
	0005-hwmon-Add-driver-for-Steam-Deck-s-EC-sensors.patch
	0006-leds-steamdeck-Add-support-for-Steam-Deck-LED.patch
	0007-extcon-Add-driver-for-Steam-Deck.patch
	0008-hwmon-steamdeck-hwmon-Add-support-for-max-battery-le.patch
	0009-mfd-steamdeck-Expose-controller-board-power-in-sysfs.patch
	0010-x86-implement-tsc-directsync-for-systems-without-IA3.patch
	0011-x86-touch-clocksource-watchdog-after-syncing-TSCs.patch
	0012-x86-save-restore-TSC-counter-value-during-sleep-wake.patch
	0013-x86-only-restore-TSC-if-we-have-IA32_TSC_ADJUST-or-d.patch
	0014-x86-don-t-check-for-random-warps-if-using-direct-syn.patch
	0015-x86-revert-extra-time-added-to-check-for-tsc-wraps.patch
	0016-usb-dwc3-Hardcode-jupiter-ACPI-device-as-extcon-name.patch
	0017-usb-dwc3-Bump-USB-gadget-wakeup-timeout.patch
	0018-usb-dwc3-Drop-usb-role-swtich-from-dwc3_pci_mr_prope.patch
	0019-usb-dwc3-Fix-linux-extcon-name.patch
	0020-pinctrl-amd-Add-quirk-to-timeout-irq-pin-reconfigura.patch
	0021-mmc-core-add-safe_trim_quirk-attribute.patch
"
builddir="$srcdir/linux-${_kernver//_/-}"

prepare() {
	default_prepare
	cp "$srcdir/$_config" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot
	make install modules_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir"/include/config/kernel.release \
		"$pkgdir"/usr/share/kernel/$_flavor/kernel.release
}

sha512sums="
53fa166da1dda6460402c6a49ba1fb2d5940e4845fa1cd853e6450761d144cbe778b73e4a4724f8a2e3156c4e0ef18a4cc3c029ae9f26a4f881129ba3ec115c1  linux-6.11.tar.gz
ca784d9ca8b8b04e54b78f89771d4785952af1491666b04c42e790576cc7c34b5a485dcbe88e0198f74226b40d76dc649faa405ef7afd2beb2a40eddb05be2a2  config-valve-jupiter.x86_64
221d8de25b902d66c5f22fec1da627be7bfe23305d2bbf5bbedb9859748e9614f4ae90339e4a779c725e2683032877e8544234ac22b354cd9f0f0d2490f86be6  0001-ACPICA-Limit-error-message-flood-caused-by-firmware-.patch
2f3f207498feba34eec85deb9962d35ce06d4145088a0cf34480eab30f94de0af27d9befa5061354d241ab0807152166208f7c22e689dcea3fa37d1756fb108e  0002-drivers-video-backlight-Disable-backlight-notificati.patch
289066f4535dbd52d750e90f5a6b573aebebcbdddafb2e50e18f3f0a67148ac2f2372acd2bc2e2bdac4363ead325ea8edfd4c323b4765054741e3a3ce3af2994  0003-iio-light-ltrf216a-Return-floating-point-values.patch
69e52390e1ffe467d9d2a45573756abd6d8a95261dd04e8460d284379787276cc656fb380809082edb3dca5487fa216da5a2ac280483c64946bf8ef9d1b28dac  0004-mfd-Add-MFD-core-driver-for-Steam-Deck.patch
9012c27d1db283caec8a1eaba1102a8bb407a546378be807702395af5f029a62815cfd195daa71be61f65bb3fed4a50bb5bef673bc870ed0465d8a83b8dc03b9  0005-hwmon-Add-driver-for-Steam-Deck-s-EC-sensors.patch
f67f5567ce6afec95128cdaecfef54b1e6e81f9f3128b2c309cd73d094caed4269f976f54e97d4b04df1089c9cf9860ebe804955691612da03703753f9f9b12b  0006-leds-steamdeck-Add-support-for-Steam-Deck-LED.patch
2244509a77361334a682ce177afaed9ffed917dc5ed31092eb898c31fb63d1efb905c89dd733393d30c395950e0fc9579bb7e80b7b3373a8af5ec00ec17f3947  0007-extcon-Add-driver-for-Steam-Deck.patch
c4f08daffdcfec47e6e497027f0e27d344d31a9b7323f577c52fa5eba50d799ba65ac1b22cbb5ec27cb01731a0a1456dd6c09e4637e9350fd2449309f28c425a  0008-hwmon-steamdeck-hwmon-Add-support-for-max-battery-le.patch
1f8e8dbf09307343b3db7b212aabe54c687ca6f0b1120375cfc6bebfa7964b16a1221b0a3e9e273fa8f39a88142180db5213627d622511fa12fbd17f2a1813b2  0009-mfd-steamdeck-Expose-controller-board-power-in-sysfs.patch
14442d9d41799b796fde1bec0978da78214b5b9186a9c73957b650c785470c23212688bd145a937ed4b3f2235eef7a66a1d23faeafafc1a91b4bbc52ff35512f  0010-x86-implement-tsc-directsync-for-systems-without-IA3.patch
7744574db76682314457b8bc798870650ec2536dc5917492c7d14c868e59d69cb36df9e3182d2a7341e47319056c7031ff2a62b7752e2fc962cf8b1506cf3844  0011-x86-touch-clocksource-watchdog-after-syncing-TSCs.patch
a18f0bd308486fe5379e5f9a25bc6b7f8e9271425ddfa23ec2815fd20716e6de1a774dbd5f0a9487a09150a54d0980ccfaed8987848638ee149d2911b58a30d7  0012-x86-save-restore-TSC-counter-value-during-sleep-wake.patch
bfbb8be83c6103e865a13c4718794fda092fea0815ed4170048621038a6300c8650c9333eb753984ee13e96874691edb8238da1fa9aae0533d23f5e7de0a1879  0013-x86-only-restore-TSC-if-we-have-IA32_TSC_ADJUST-or-d.patch
2bb59814f6e095dbef5694a07704b5530f5061a217c53b3a576988b57ae4ca6fee831d50b6116c92b2cb187e488b0123b11b0bc33e5a117d1f9a6da25cc5539f  0014-x86-don-t-check-for-random-warps-if-using-direct-syn.patch
85bce585ac3336c1ebc528f97f5e4d03a56c7ff3d3d1e7a356c0f6218eb143bace1962481640c81aadac7e0e00eddc8e611b7c8886c1238e0fd179cc38513b8c  0015-x86-revert-extra-time-added-to-check-for-tsc-wraps.patch
d6fde7914429f08d7c017c35d9a4176f1a6816303ff2e6b5b7e3128d26c646d9d01d66c1cfc1b634f52d770a4c7b6e3247084049d801e70480eabbd7608e931e  0016-usb-dwc3-Hardcode-jupiter-ACPI-device-as-extcon-name.patch
22aa5766a0ffaf1383a51dd7308cc0bdad7900069ccce218b31e63b2bc229c538315915b05dd912586083dfd2e0418ca3d9e0ea7e8a61b67d78aac60d95c6de3  0017-usb-dwc3-Bump-USB-gadget-wakeup-timeout.patch
7261eb068eb2b886ef9733a6fc1b2b0c6c3a914f219317b9f0e1e314fa378be328dc7d9fe08663cd66c41541ede33ac3346e0f92c32e9bedecf6c2117a2447bc  0018-usb-dwc3-Drop-usb-role-swtich-from-dwc3_pci_mr_prope.patch
b1f6bb73bb5539c4f912ab79d2eaa978e8522a1a1597362c6a22535bd1cc4726222d4ef56c9541f4107e744ac613100eaf763b8fe6afbd12a5383a692d15e905  0019-usb-dwc3-Fix-linux-extcon-name.patch
1d882784f2dd60048570a7e76f02a00c7670bcfaf45cd4fdd96ec308265264482361852c609a97ff24931200df1d7f6268583c89e00aa91ac44c2db013ef87b8  0020-pinctrl-amd-Add-quirk-to-timeout-irq-pin-reconfigura.patch
7702b0beb85c8059f71df26fc9b36ecdf995d49116c7f8dbc642635dcc50dbaaacf6a8de22f3b0b0c7e73800d350c0205eea44a548292a227a6a8d7cba44b06b  0021-mmc-core-add-safe_trim_quirk-attribute.patch
"
